package com.dc.dbus.netty.node;

import com.dc.dbus.netty.ITestService;
import com.dc.dbus.session.client.Client;
import com.dc.dbus.session.listener.ClientSideEventListener;
import com.dc.dbus.session.register.ServiceRegister;
import com.dc.dbus.session.register.ZookeeperServiceRegister;
import com.dc.dbus.transport.netty.client.NettyClientSideTransport;

public class NettyClient {

    protected final static ClientSideEventListener clientSideEventListener = new ClientSideEventListener() {
        @Override
        public void exception(String message, Exception e) {
            System.err.println(message);
            e.printStackTrace(System.err);
        }
    };

    public static void main(String[] args) throws Exception {

        NettyClientSideTransport clientSideTansport = new NettyClientSideTransport(2);

        ServiceRegister serviceRegister = ZookeeperServiceRegister.getClientSideReiger("127.0.0.1:2181",
                clientSideTansport.getServiceChangeListener());

        Client client = new Client(serviceRegister, clientSideTansport, clientSideEventListener);

        ITestService clientStub = client.createClientStub(ITestService.class.getName(), ITestService.class);

        String node = "node_0000000004";

        System.out.println( clientStub.test1(node, "111111") );

        System.out.println( clientStub.test1(node, "111111") );

        System.out.println( clientStub.test1(node, "111111") );

        System.out.println( clientStub.test2(node, "111111") );

        System.out.println( clientStub.test3(node, "111111") );
    }
}
